<template>
	<view>
		<view class="back-home" @click="backhome()">
			<image src="./ss.png"></image>
		</view>
		<view class="page-title">厅堂开门纳财营销登记/派券</view>
		<view class="container" style="display: flex;justify-content: center;flex-direction: column;">
			<view style="margin: 15px;padding-top: 5px;">
				<view style="display: flex;justify-content: center;flex-direction: column;" v-for="item in inputlist">
					<view class="xxcontain">
						<view style="margin-top: 10px;color:#808080;font-size: 15px;">
							* {{item.label}}
						</view>
						<input v-if="item.prop!='custTel'"
							style="color: #000000;margin-top: 20px;margin-left:10px;: #555;width: 83%;float: left;"
							type="text" v-model="form[item.prop]" />
						<input v-if="item.prop=='custTel'"
							style="color: #000000;margin-top: 20px;margin-left:10px;: #555;width: 83%;float: left;"
							type="text" v-model="form[item.prop]" />
						<view class="customTelDigt" v-if="item.prop=='custTel'" style="margin-top: 20px;">
							<text style="width: 10%;color:#808080;">{{form[item.prop].length}}/11</text>
						</view>
						<view class="xhx">
							<view style="width: 93%;height:1px;margin-left:10px;background-color: #dadada;float: left;">
							</view>
						</view>
					</view>
				</view>
				<view style="margin-top: 20px;">
					<view class="crz-btn" style="background: #1989fa;" @click="apply(4)">
						仅登记提交（限50万以上客户）
					</view>
					<view style="display: flex;">
						<view class="crz-btn" style="flex: 1;" @click="apply(1)">
							登记并派券(88元)
						</view>
						<view class="crz-btn" style="flex: 1;" @click="apply(3)">
							登记并派券(300元)
						</view>
					</view>
					<view style="color: #666;font-size: 32rpx;margin-top: 20rpx;">
						提示：参加开门纳财活动的客户不得与参与新年壕礼活动的客户重复，客户只能参与其中一个活动!
					</view>

					<view style="display: flex;position: fixed;bottom: 0;width: 100%;box-sizing: border-box;left: 0;">
						<view class="crz-btn2" style="flex: 1;background:#ff976a" @click="goToRecord2">
							已登记客户查询
						</view>
						<view class="crz-btn2" style="flex: 1;background:#ff976a" @click="goToRecord">
							派券客户查询
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import jscookie from '../js.cookie.js'
	import Watermark from '../watermark.js';

	export default {
		data() {
			return {
				inputVal: '',
				timeout: null,
				empty: {},
				custOriName: '',
				inputlist: [{
					prop: 'custTel',
					label: '客户手机号',
					type: '',
					option: ''
				}, {
					prop: 'custName',
					label: '客户姓名',
					type: '',
					option: ''
				}, {
					prop: 'custId',
					label: '客户号',
					type: '',
					option: ''
				}],
				form: {
					custTel: "",
					custName: "",
					custId: ''
				},
				getCustNameParam: {
					custTel: ""
				}
			}
		},
		onShow: function() {
			uni.showLoading({
				title: 'Loading'
			});
			setTimeout(() => {
				if (process.env.employeeId) {
					uni.setStorageSync('userToken', process.env.employeeId);
				} else {
					uni.request({
						url: window.location.origin + '/mobilereport_stage/api/usap-users-bind',
						// url: 'https://app.xm.abchina.com.cn/mobilereport_stage/api/usap-users-bind',
						method: 'GET',
						success: (res) => {
							uni.setStorageSync('userToken', res.data.employeeId);
							if (res.data.name != undefined) {
								this.username = res.data.name
								Watermark.set(res.data.name)
							} else {
								window.location.href = window.location.origin +
									'/mobilereport_stage/'
							}
						},
						fail: (res) => {
							uni.hideLoading();
							console.log(res);
							window.location.href = 'https://jupyter.xm.abc/mobilereport_stage/'
						}
					});
				}


				if (process.env.employeeId) {
					uni.setStorageSync('authenticationToken', process.env.authenticationToken);
				} else {
					if (jscookie.get('authenticationToken') != undefined) {
						try {
							if (process.env.employeeId) {
								uni.setStorageSync('authenticationToken', "suxiang2023!");
							} else {
								uni.setStorageSync('authenticationToken', jscookie.get('authenticationToken'));
							}
						} catch (e) {
							window.location.href = 'https://jupyter.xm.abc/mobilereport_stage/'
						}

					}
				}

				try {
					if (uni.getStorageSync('authenticationToken') == undefined) {
						window.location.href = 'https://jupyter.xm.abc/mobilereport_stage/'
					} //取身份
				} catch (e) {
					window.location.href = 'https://jupyter.xm.abc/mobilereport_stage/'
				}
				uni.hideLoading();
			}, 1000)
		},
		onLoad(options) {

			if (options.newsType) {
				this.newsType = options.newsType
			}
			//#ifdef H5
			uni.setNavigationBarTitle({
				title: options.typeName ? options.typeName : ""
			});
			window.document.title = options.typeName ? options.typeName : "";
			//#endif
		},
		onHide() {},
		methods: {
			copyprizeCode(str) {
				var jsCode = str; // 示例中的JS代码

				// 创建一个临时元素并设置其值为需要复制的文本内容
				var tempElement = document.createElement("textarea");
				tempElement.value = jsCode;
				document.body.appendChild(tempElement);

				// 选中该临时元素的所有文本内容
				tempElement.select();
				tempElement.setSelectionRange(0, 9999999); /* For mobile devices */

				// 复制选中的文本内容到剪贴板
				document.execCommand("copy");

				// 移除临时元素
				document.body.removeChild(tempElement);
				uni.showToast({
					title: '复制成功',
					icon: 'none'
				})
			},
			getCustName() {
				if (this.form["custTel"].length == 11) {
					this.getCustNameParam.custTel = this.form["custTel"]
					this.ajax(this.getCustNameParam, "Ttkmnc/CustInfo/getCustNameByCustId", "getCustNameByCustId")
				}
			},
			goToRecord2() {
				uni.navigateTo({
					url: '../ttkmnk/custInfolist'
				})
			},
			goToRecord() {
				uni.navigateTo({
					url: '../ttkmnk/applyRecord'
				})
			},
			backhome() {
				window.location.href = window.location.origin + '/mobilereport_stage/'
			},

			apply(str) {
				if (this.form.custTel.length != 11) {
					uni.showModal({
						title: '手机号位数有误！',
						showCancel: false
					});
				} else if (this.form.custName.length < 2) {
					uni.showModal({
						title: '客户姓名格式有误！',
						showCancel: false
					});
				} else if (!this.form.custId) {
					uni.showModal({
						title: '请输入客户ID！',
						showCancel: false
					});
				} else {
					let that = this
					if (str == 4) {
						this.ajax(this.form, "TtkmncNew/CustInfo/insert", "apply")
					} else {
						this.form.status = str
						uni.showModal({
							title: '提示',
							content: '是否确认派券？',
							confirmText: `派券(${str==1?'88元':'300元'})`,
							success(res) {
								if (res.confirm) {
									uni.showLoading({
										title: '加载中'
									})
									that.ajax(that.form, "Ttkmnc/CustInfo/insert", "apply")
								}

							}
						})
					}


				}
			},
			ajax: function(da, ur, key) { //封装ajax
				uni.request({
					// url: ur, //仅为示例，并非真实接口地址。
					url: this.$store.url.yuming + ur, //仅为示例，并非真实接口地址。
					data: da,
					method: 'POST',
					header: {
						'Content-Type': 'application/json;',
						token: uni.getStorageSync('authenticationToken'),
						// 'token':'suxiang_testToken',
					},
					success: (res) => {
						uni.hideLoading()
						if (res.data.code == "0000") {
							if (key == 'apply') { //提交
								if (res.data.data) {
									uni.showModal({
										title: '提交成功',
										content: res.data.data,
										showCancel: true,
										cancelText: '关闭',
										confirmText: '复制信息',
										success(res2) {
											if (res2.confirm) {
												that.copyprizeCode(res.data.data)
											}
										}
									});
								} else {
									uni.showModal({
										title: '提交成功',
										showCancel: false
									});

								}
								this.form.custTel = ""
								this.form.custName = ""
							}
							if (key == 'getCustNameByCustId') { //提交
								this.form.custName = res.data.data.custName.replace(res.data.data.custName
									.substring(1, 2), '*')
							}
						} else {
							if (res.data.msg) {
								uni.showModal({
									title: res.data.msg,
									showCancel: false
								});
							} else {
								uni.showModal({
									title: res.data.message,
									showCancel: false
								});
							}
						}
					}
				});
			}
		}
	}
</script>

<style>
	.back-home {
		position: fixed;
		right: 20rpx;
		bottom: 120rpx;
		padding: 10px;
		border-radius: 50%;
		overflow: hidden;
		box-shadow: darkgrey 0px 0px 10rpx 5rpx;
		background: #fff;
		z-index: 99;
	}

	.back-home image {
		width: 50rpx;
		height: 50rpx;
		display: block;

	}

	.page-title {
		color: #555;
		font-weight: 800;
		margin: 20rpx 20rpx 0 20rpx;
		font-size: 32rpx;
		display: flex;
		align-items: center;
	}

	.page-title::before {
		content: ' ';
		width: 16rpx;
		height: 40rpx;
		background: #31C8B6;
		margin-right: 20rpx;

	}

	.apply-content {
		background: #fff;
		margin: 20rpx;
		margin-bottom: 0;
		margin-top: 10rpx;
		border-radius: 20rpx;
		overflow: hidden;
	}

	.apply-content-title {
		font-size: 34rpx;
		font-weight: 700;
		color: #555;
		padding: 20rpx 30rpx;

	}

	.apply-content-cell-left {
		flex-shrink: 0;
		margin-right: 20rpx;
		font-size: 34rpx;
		color: #555;
	}

	.apply-content-cell-right {
		flex: 1;
	}

	.apply-content-cell {
		display: flex;
		padding: 20rpx 0;
		border-bottom: 1px solid #e5e5e5;
	}

	.apply-content-cell-input {
		text-align: center;
	}

	.crz-btn {
		font-size: 32rpx;
		height: 88rpx;
		line-height: 88rpx;
		background-color: #0b9b89;
		color: #FFFFFF;
		border-radius: 44rpx;
		text-align: center;
		margin: 10rpx;
	}

	.crz-btn2 {
		font-size: 32rpx;
		height: 88rpx;
		line-height: 88rpx;
		background-color: #0b9b89;
		color: #FFFFFF;
		border-right: 1px solid #ccc;
		text-align: center;
	}

	.crz-btn2:last-child {
		border: 0;
	}
</style>